using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using CreamX.Framework.Game.ParticleEffects;
using Microsoft.Xna.Framework;
using CreamX.Framework.Game.GameEngine;

namespace CreamX.Framework.Game
{
    public class CreamXParticleEffect: CreamXObject
    {

        public enum ParticleShape
        {
            Point,
            Circle
        }
        public ParticleShape Shape=ParticleShape.Point;
        public float CircleRadius = 50;
        public CreamXParticleEffect()
        {
        }
        Vector2 _emitPosition;
        float _emitRotation;
        public override void Update(float gameTime)
        {
            if (Shape == ParticleShape.Circle)
            {
                _emitRotation += gameTime;
                if (_emitRotation < 0)
                    _emitRotation += MathHelper.TwoPi;
                else if (_emitRotation > MathHelper.TwoPi)
                    _emitRotation -= MathHelper.TwoPi;

                for (int i = 0; i < 360; i+=36)
                {
                    float rot = MathHelper.ToRadians(i);
                    Vector2 __po = new Vector2((float)Math.Cos(rot), (float)Math.Sin(rot));
                    _emitPosition = Position + (__po * CircleRadius);
                    _emitter.AddParticles(_emitPosition,5);
                }
            }
            else
            {
                _emitPosition = Position;

                _emitter.AddParticles(_emitPosition);
            }
            _emitter.Update(CreamXGameEngine.Instance.Elapsed);
            base.Update(gameTime);
        }
        public override void OnRegister()
        {
            //SetupEmitter();
            base.OnRegister();
        }
        public override void Draw(SpriteBatch spritebatch)
        {
            _emitter.Draw(CreamXGameEngine.Instance.Elapsed, spritebatch);
        }
        
        public void SetupEmitter()
        {
            _emitter.Init();
            
        }
        public Emitter _emitter;
        
        public float _life;
    }

   
}
